// pages/mycent/mycent.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentid:0,
        wholes:"",
        goods:[],
        waitpays:"",
        Receiving:""
    },
    tap(e){
        console.log(e)
        console.log(e.target.dataset.tapid)
        var that = this
        that.setData({currentid:e.target.dataset.tapid})
        console.log("123",this.data.goods);
        console.log("234",this.data.wholes);
      },
    GoodsCarListsFun(){
        let date=new Date();
        //年
        let year=date.getFullYear();
        //月
        let month=date.getMonth()+1;
        //日
        let day=date.getDate();
        //时
        let hh=date.getHours();
        //分
        let m=date.getMinutes();
        let mm = m < 10? "0" + m : m
        //秒
        let s=date.getSeconds();
        let  ss =s<10?"0"+s:s;
        let rq=year+"-"+month+"-"+day+"-"+hh+":"+mm+":"+ss;
        let GoodsCarLists = wx.getStorageSync('GoodsCarLists');
        let goods = []

        if(GoodsCarLists){
            GoodsCarLists.forEach(element => {
                let {id,goodsName,goodsPrice,goodsImage,num}=element;
                let  GoodsCarLis = {
                 id,
                 goodsName,
                 goodsPrice,
                 goodsImage,
                 num,
                 rq
                }
                goods.push(GoodsCarLis);
             });
        }else{
            let {id,goodsName,goodsPrice,goodsImage,num}=GoodsCarLists;
            let  GoodsCarLis = {
                 id,
                 goodsName,
                 goodsPrice,
                 goodsImage,
                 num,
                 rq
                }
                goods.push(GoodsCarLis);
        }
        this.setData({
            goods:goods
        })
      },
    immPay(e){
        let date=new Date();
        //年
        let year=date.getFullYear();
        //月
        let month=date.getMonth()+1;
        //日
        let day=date.getDate();
        //时
        let hh=date.getHours();
        //分
        let m=date.getMinutes();
        let mm = m < 10? "0" + m : m;
        //秒
        let s=date.getSeconds();
        let  ss =s<10?"0"+s:s;
        let rq=year+"-"+month+"-"+day+"-"+hh+":"+mm+":"+ss;
        console.log(e.target.dataset.index);
        let index = e.target.dataset.index;
        let wholes = wx.getStorageSync('wholes');
        let GoodsCarList = [];
        let copms = []
        if(wholes[index].flag == 1){
            GoodsCarList.push(wholes[index]);
            wx.setStorageSync("GoodsCarLists",GoodsCarList)
            wx.navigateTo({
              url: '/pages/pays/pays?index=' + index,
            })
        }else if(wholes[index].flag == 2){
            let{ 
                ids,
                goodsName,
                goodsPrice,
                num,
                goodsImage
            } = wholes[index];
            let copm = {
                flag:3,
                ids,
                goodsName,
                goodsPrice,
                num,
                goodsImage,
                rq
            };
            copms.push(copm);
            if(wholes){
                wholes.splice(index,1);
                for(let i = 0;i<copms.length;i++){
                    wholes.push(copms[i]);
                    wx.setStorageSync("wholes",wholes); 
                }
            }else{
               wx.setStorageSync("wholes",copms); 
            }
            this.setData({
                wholes:wholes
            })
            
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let wholes = wx.getStorageSync('wholes');
        let waitpays = wx.getStorageSync('waitpays');
        let Receiving  = wx.getStorageSync('Receiving ');
        this.setData({
            wholes,
            waitpays,
            Receiving
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.GoodsCarListsFun();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        wx.switchTab({
          url: '/pages/my/my',
        })
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})